<template>
  <div>
    <login-logo/>
   <div class="signUp">
     <div class="signUp-head" >
       <span >用户注册</span>
     </div>
     <el-form :model="registerForm" ref="registerForm" label-width="70px" class="demo-ruleForm" :rules="rules" size="mini">
       <el-form-item prop="username" label="用户名" >
         <el-input v-model="registerForm.username" placeholder="用户名" ></el-input>
       </el-form-item>
       <el-form-item prop="password" label="密码" size="mini">
         <el-input v-model="registerForm.password" placeholder="密码" ></el-input>
       </el-form-item>
       <el-form-item prop="sex" label="性别">
         <el-radio-group v-model="registerForm.sex">
           <el-radio :label="0">男</el-radio>
           <el-radio :label="1">女</el-radio>
         </el-radio-group>
       </el-form-item>
       <el-form-item prop="phone" label="手机">
         <el-input v-model="registerForm.phone" placeholder="手机"></el-input>
       </el-form-item>
       <el-form-item prop="email" label="邮箱">
         <el-input v-model="registerForm.email" placeholder="邮箱"></el-input>
       </el-form-item>
       <el-form-item prop="birth" label="生日">
         <el-date-picker v-model="registerForm.birth" placeholder="请选择生日" style="width: 100%"></el-date-picker>
       </el-form-item>
       <el-form-item prop="introduction" label="介绍">
         <el-input v-model="registerForm.introduction" placeholder="介绍"></el-input>
       </el-form-item>
       <div class="login-btn" >
         <el-button @click="goBack(-1)" size="mini" style="width: 100px;margin-left: 50px;border-radius:5px;">取消</el-button>
         <el-button type="primary" @click="SignUp" size="mini" style="width: 100px;margin-right: 50px;border-radius:5px;">确定</el-button>
       </div>
     </el-form>
   </div>
  </div>
</template>

<script>
import loginLogo from '../components/loginLogo'
import {rules} from '@/assets/data/form'
import {mixin} from "@/mixins";
import {SignUp} from '../api/index'

export default {
  name: "Sign-up",
  mixins:[mixin],
  components:{
    loginLogo
  },
  data(){
    return {
      registerForm:{
        username:'',//用户名
        password:'',//密码
        sex:'',//性别
        phone:'',//手机
        email:'',//邮箱
        birth:'',//生日
        introduction:'',//介绍
      },
      rules:{}, //表单提交的规则
    }
  },
  created() {
    this.rules = rules
  },
  methods:{
    //确定
    SignUp(){
      let _this = this;
      let d = this.registerForm.birth;
      let dateTime = d.getFullYear() + '-' +(d.getMonth()+1)+'-'+d.getDate();
      let params = {
        ...this.registerForm,
        birth:dateTime,
        avatar:'https://p9.itc.cn/q_70/images03/20230518/63b24f7da6234d33ac797fdd958e05eb.png'
      }
      SignUp(params).then(res =>{
        if(res.code ===200){
          _this.notify('注册成功','success');
          setTimeout(function (){
            _this.$router.push({path:'/login-in'});
          },2000);
        }else {
          _this.notify('注册失败','error')
        }
      }).catch(error => {
        _this.notify('注册失败','error');
      })
    },
    //取消
    goBack(index){
      this.$router.go(index);
    }
  }
}
</script>

<style lang="scss" scoped>
@import "../assets/css/sign-up.scss";
</style>
